package com.ahdms.es.gm.asn1.generic;

import org.bouncycastle.asn1.*;

public class ECCPoint extends ASN1Object {

    private ASN1Integer x;
    private ASN1Integer y;

    public static ECCPoint getInstance(Object o) {
        if (o instanceof ECCPoint) {
            return (ECCPoint) o;
        } else if (o instanceof ASN1Sequence) {
            return new ECCPoint((ASN1Sequence) o);
        }

        throw new IllegalArgumentException("unknown object in factory: " + o);
    }

    public ECCPoint(ASN1Sequence seq) {
        x = ASN1Integer.getInstance(seq.getObjectAt(0));
        y = ASN1Integer.getInstance(seq.getObjectAt(1));
    }

    public ECCPoint(ASN1Integer x, ASN1Integer y) {
        this.x = x;
        this.y = y;
    }

    public ASN1Integer getX() {
        return x;
    }

    public ASN1Integer getY() {
        return y;
    }

    @Override
    public ASN1Primitive toASN1Primitive() {
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(x);
        v.add(y);
        return new DERSequence(v);
    }

}
